<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 1. 先准备一个容器 -->
    <div id="app">
      <input type="text" v-model.number="a" />
      <input type="text" v-model.number="b" />
      <button @click="sum">求和</button>
      <p>{{total}}</p>
      <hr />
      <input type="text" v-model.trim="msg" @keyup.enter="fn" />
      <hr />
      <!-- 原理：默认情况下v-model内部是oninput事件，lazy就把oninput变成onchange事件 -->
      <input type="text" v-model.lazy="txt" />
      <p>{{txt}}</p>
    </div>
    <!-- 2. 引框架 -->
    <script src="./vue.js"></script>
    <script>
      // 3.初始化vue实例对象
      const vm = new Vue({
        el: "#app",
        data: {
          a: 0,
          b: 0,
          total: 0,
          msg: "",
          txt: "",
        },
        methods: {
          sum() {
            // this.total = Number(this.a) + Number(this.b);
            this.total = this.a + this.b;
          },
          fn() {
            console.log(this.msg);
          },
        },
      });
    </script>
  </body>
</html>



